package com.alpha.task.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alpha.core.controller.BaseController;
import com.alpha.core.tools.ResultInfo;
import com.alpha.task.service.CountDownService;
/**
 * 倒计时任务触发接口
 * @author Administrator
 *
 */

@RestController
@RequestMapping("task/countDown")
public class CountDownController extends BaseController{
		
		@Autowired
		private CountDownService countDownService;
		
		/**
		 * 装置未加载的任务开始执行
		 * @return
		 */
		@RequestMapping("loadAndToStart")
		public ResultInfo loadAndToStart(){
			logger.info("CountDownController loadAndToStart ");
			try{
				countDownService.toStartUnloadTask();
			}catch (Exception e) {
				e.printStackTrace();
				ResultInfo.getDefeatResult();
			}
			return ResultInfo.getSuccessResult();
		}
		
		/**
		 * 根据id指定加载一个任务
		 * @return
		 */
		@RequestMapping("startTaskById/{id}")
		public ResultInfo startTaskById(@PathVariable Long id){
			logger.info("CountDownController startTaskById id :  " + id);
			if(id == null || id == 0){
				return ResultInfo.getDefeatResult();
			}
			try{
				countDownService.startTaskById(id);
			}catch (Exception e) {
				e.printStackTrace();
				return	ResultInfo.getDefeatResult();
			}
			return ResultInfo.getSuccessResult();
		}
		
		/**
		 * 根据id指定加载一个任务
		 * @return
		 */
		@RequestMapping("modifyAndStartTask")
		public ResultInfo modifyAndStartTask(){
			logger.info("CountDownController modifyAndStartTask");
			try{
				countDownService.modifyAndStartTask();
			}catch (Exception e) {
				e.printStackTrace();
				return	ResultInfo.getDefeatResult();
			}
			return ResultInfo.getSuccessResult();
		}
		
		
	
}
